package com.sy.controller;

import com.sy.dto.PageBean;
import com.sy.entity.*;
import com.sy.service.HomeWorkService;
import com.sy.service.QuestionService;
import com.sy.service.StudentHomeService;
import com.sy.service.TeacherService;
import com.sy.vo.AnswerVo;
import com.sy.vo.HomeworkVo;
import com.sy.vo.StudentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author:范富强
 * @Date: 2021/10/11 0011 18:59
 */

@RestController
public class TeacherController {

    @Autowired
    private TeacherService teacherService;
    @Autowired
    private QuestionService questionService;
    @Autowired
    private StudentHomeService studentHomeService;


    /**
     * cxl
     * 获取老师所有基本
     */
    @RequestMapping(value = "allTeachers", method = RequestMethod.GET)
    public List<Teacher> getAllTeacherInfo() {
        return teacherService.getAllTeacherInfo();
    }

    /**
     * 获取当前教师布置的作业 fma
     * 前端请求路劲  http://localhost:8888/teachers?tno=2
     */
    @RequestMapping(value = "teachers", method = RequestMethod.GET, params = {"tno"})
    public Teacher getTeacherByTno(@RequestParam("tno") Integer tno) {
        return teacherService.getTeacherByTno(tno);
    }

    /**
     * @Author:zhf 回复问题
     */
    @RequestMapping(value = "answer", method = RequestMethod.POST)
    public Boolean answerQue(@RequestBody AnswerVo answerVo) {

        return questionService.addReply(answerVo);
    }

    /**
     * @Author:zhf 教师根据标题查询作业
     */
    @RequestMapping(value = "homeworks", method = RequestMethod.GET, params = {"limit", "pageNo", "pageNum", "title"})
    public List<CheckHome> getStudentHomeWorksByTitle(String limit, String title,Integer pageNo,Integer pageNum) {

        List<CheckHome> studentHomeWorksByTitle = studentHomeService.getStudentHomeWorksByTitle(limit, title,pageNo,pageNum);

        return studentHomeWorksByTitle;
    }

    /**
     * @Author:cxl 教师根据标题查询作业总数
     */
    @RequestMapping(value = "homeworks/num", method = RequestMethod.GET, params = {"limit","title"})
    public Integer getStuHomeNum(@RequestParam(name = "limit") String limit, @RequestParam(name = "title", required = false) String title) {
        return studentHomeService.getStuHomeNum(limit, title);
    }



}